package com.ia.aistream.manager.system.impl;

import com.ia.aistream.common.utils.DateUtils;
import com.ia.aistream.common.utils.StringUtils;
import com.ia.aistream.manager.system.ISysUserOnlineManager;
import com.ia.aistream.mapper.system.SysUserOnlineMapper;
import com.ia.aistream.model.system.entity.SysUserOnline;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/***
 * 用户在线信息
 */
@Component
public class SysUserOnlineManagerImpl implements ISysUserOnlineManager {

    @Autowired
    private SysUserOnlineMapper userOnlineDao;

    @Override
    public void deleteOnlineById(String sessionId) {
        SysUserOnline userOnline = userOnlineDao.selectOnlineById(sessionId);
        if (StringUtils.isNotNull(userOnline))
        {
            userOnlineDao.deleteOnlineById(sessionId);
        }

    }

    @Override
    public void batchDeleteOnline(List<String> sessions) {
        for (String sessionId : sessions)
        {
            SysUserOnline userOnline = userOnlineDao.selectOnlineById(sessionId);
            if (StringUtils.isNotNull(userOnline))
            {
                userOnlineDao.deleteOnlineById(sessionId);
            }
        }
    }

    @Override
    public List<SysUserOnline> selectOnlineByExpired(Date expiredDate) {
        String lastAccessTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, expiredDate);
        return userOnlineDao.selectOnlineByExpired(lastAccessTime);
    }
}
